package com.ms.teapuesto.service;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import com.ms.teapuesto.bean.LigaBean;
import com.ms.teapuesto.model.*;
import com.ms.teapuesto.persistence.jpa.*;
import com.ms.teapuesto.util.HtmlUtil;
import com.ms.teapuesto.util.StringUtil;
import com.ms.teapuesto.web.LiveScoreHtml;
import freemarker.template.SimpleDate;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

//import javax.annotation.Nullable;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by RAZANERO on 2/09/14.
 */
@Component
public class LigaServiceImpl implements LigaService {


    private static final Logger LOG = LoggerFactory.getLogger(LigaServiceImpl.class);


    @Autowired
    private LigaRepository ligaRepository;

    @Autowired
    private EquipoRepository equipoRepository;

    @Autowired
    private EventoRepository eventoRepository;

    @Autowired
    private FechaRepository fechaRepository;

    @Autowired
    private PronosticoRepository pronosticoRepository;

    @Autowired
    private AnalisisService analisisService;

    @Autowired
    private EventoService eventoService;


    @Transactional(propagation = Propagation.REQUIRED)
    public void descargarLigas() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setJavaScriptEnabled(false);
        webClient.setThrowExceptionOnFailingStatusCode(false);
        String URL = "http://www.soccerstats.com/";
        HtmlPage mainPage = webClient.getPage(URL + "leagues.asp");
        HtmlTable detalleTable = HtmlUtil.getHtmlTable(mainPage, 4);
        List<HtmlTableRow> rows = detalleTable.getRows();
        List<Liga> ligaList = new ArrayList<Liga>();
        for (int j = 1; j < rows.size(); j++) {
            HtmlTableRow detailDataRow = rows.get(j);
            Liga liga = new Liga();
            liga.setNombre(detailDataRow.getCell(0).getTextContent().replace('\n', ' ').replace((char) 160, ' ').trim());
            liga.setUrl(URL + detailDataRow.getCell(0).getHtmlElementsByTagName("a").get(0).getAttribute("href"));
            ligaList.add(liga);
        }
        Liga ligaPeru = new Liga();
        ligaPeru.setNombre("PERU");
        ligaPeru.setLeagueId("PER");
        ligaPeru.setUrl_campeonato("http://www.livescore.com/soccer/peru/primera-division-apertura/results/7-days/");
        ligaList.add(ligaPeru);
        Liga ligaPeru2 = new Liga();
        ligaPeru2.setNombre("PERU2");
        ligaPeru2.setLeagueId("PE2");
        ligaPeru2.setUrl_campeonato("http://www.livescore.com/soccer/peru/segunda-division/results/7-days/");
        ligaList.add(ligaPeru2);
        for (Liga liga : ligaList) {
            populateLeagueId(liga);
            ligaRepository.save(liga);
        }
    }

    @Transactional
    public void descargarFechas(List<LigaBean> ligaBean) {
        for (LigaBean bean : ligaBean) {
            descargarFechasIntern(bean);
            eventoService.asignarResultadoFinal(bean.getLeagueId());
        }
    }

    @Override
    public void descargarPredictz() {
        descargarPronosticoIntern();
        eventoService.asignarPronostico();

    }

    @Transactional
    private void descargarPronosticoIntern() {
        List<Liga> ligaList = ligaRepository.getLigaList();

        Map<String, String> leagueIdNameMap = new HashMap<String, String>();

        List<Liga> predictzList = new ArrayList<Liga>();
        for (Liga liga : ligaList) {
            if (StringUtils.isNotBlank(liga.getLeagueNamePredictz())) {
                leagueIdNameMap.put(liga.getLeagueNamePredictz(), liga.getNombre());
                predictzList.add(liga);
            }
        }

        try {

            for (Iterator<Liga> iterator = predictzList.iterator(); iterator.hasNext(); ) {
                Liga liga = iterator.next();
                List<Pronostico> pronosticoList = (LiveScoreHtml.downloadPredictz(liga.getUrlPredictz()));
                LOG.info("Total de pronosticoList ult 7 <" + pronosticoList.size() + ">");
                for (Pronostico pronostico : pronosticoList) {
                    pronostico.setLiga(liga.getNombre());
                    pronostico.setInUsado("0");
                    pronosticoRepository.save(pronostico);
                }
            }
        } catch (Exception e) {
            LOG.error("Error al descarga pronosticoList para la liga ", e);
        }
    }

    @Transactional
    private void descargarWinDrawWinIntern() {
        List<Liga> ligaList = ligaRepository.getLigaList();

        Map<String, String> leagueIdNameMap = new HashMap<String, String>();

        List<Liga> predictzList = new ArrayList<Liga>();
        for (Liga liga : ligaList) {
            if (StringUtils.isNotBlank(liga.getLeagueNameWinDrawWin())) {
                leagueIdNameMap.put(liga.getLeagueNameWinDrawWin(), liga.getNombre());
                predictzList.add(liga);
            }
        }
        List<String> nameList=new ArrayList<String>();
        try {

            List<Pronostico> pronosticoList = new ArrayList<Pronostico>();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
            DateTime dt= new DateTime();
            Date tomorrow=dt.plusDays(3).toDate();
            pronosticoList.addAll(LiveScoreHtml.downloadWinDrawWin("http://www.windrawwin.com/predictions/today/"));
            pronosticoList.addAll(LiveScoreHtml.downloadWinDrawWin("http://www.windrawwin.com/predictions/tomorrow/"));
            pronosticoList.addAll(LiveScoreHtml.downloadWinDrawWin("http://www.windrawwin.com/predictions/future/"+sdf.format(tomorrow)+"/"));

                for (Pronostico pronostico : pronosticoList) {
                    if(leagueIdNameMap.get(pronostico.getLiga())==null) continue;
                    pronostico.setLiga(leagueIdNameMap.get(pronostico.getLiga().trim()));
                    pronostico.setInUsado("0");
                    nameList.add(pronostico.getEquipo1()+"-"+pronostico.getEquipo2());
                    pronosticoRepository.save(pronostico);
                }
        } catch (Exception e) {
            LOG.error("Error al descarga pronosticoList para la liga ", e);
        }
        Collections.sort(nameList);
        for (Iterator<String> iterator = nameList.iterator(); iterator.hasNext(); ) {
            System.out.println("zzzzzzzzzz"+iterator.next());

        }
    }

    @Transactional
    public void descargarHoy() {
        descargarHoyIntern();
        eventoService.asignarResultadoFinal(null);

    }

    @Transactional
    public void analizarFechas() {
        List<Liga> liga = ligaRepository.getLigaList();
        for (Liga bean : liga) {
            analizarFechas(bean);
            analizarResultados(bean);
        }
        eventoService.analizarUltEventos();
    }

    @Transactional
    public void descargarFechasIntern(LigaBean ligaBean) {
        Liga liga = ligaRepository.findOne(ligaBean.getNombre());

        if (StringUtils.isBlank(liga.getUrl_campeonato())) return;

        LOG.info("Analizando liga <" + liga.getNombre() + ">");
        List<Fecha> fechaList = new ArrayList<Fecha>();
        try {
           /* if (ligaBean.getLeagueId() != null && ligaBean.getLeagueId().equals("PER")) {
                for (int i = 0; i < 3; i++) {
                    if (i == 0)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/peru/copa-inca-group-a/results/7-days/");
                    if (i == 1)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/peru/copa-inca-group-b/results/7-days/");
                    if (i == 2)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/peru/copa-inca-group-c/results/7-days/");
                    fechaList = LiveScoreHtml.downloadFecha(liga);
                    LOG.info("Total de fechas ult 7 <" + fechaList.size() + ">");
                    for (Fecha fecha : fechaList) {
                        analisisService.execute(fecha);
                        fechaRepository.save(fecha);
                    }
                }
                LOG.info("Liga " + liga.getNombre() + " total fechas " + fechaList.size());
            } else */
            if (ligaBean.getLeagueId() != null && ligaBean.getLeagueId().equals("BEL")) {
                for (int i = 0; i < 4; i++) {
                    if (i == 0)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/belgium/play-off-i/results/all/");
                    if (i == 1)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/belgium/play-off-ii-group-a/results/all/");
                    if (i == 2)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/belgium/play-off-ii-group-b/results/all/");
                    if (i == 3)
                        liga.setUrl_campeonato("http://www.livescore.com/soccer/belgium/play-off-iii/results/all/");
                    fechaList = LiveScoreHtml.downloadFecha(liga);
                    LOG.info("Total de fechas ult 7 <" + fechaList.size() + ">");
                    for (Fecha fecha : fechaList) {
                        analisisService.execute(fecha);
                        fechaRepository.save(fecha);
                    }
                }
                LOG.info("Liga " + liga.getNombre() + " total fechas " + fechaList.size());
            } else {
                fechaList = LiveScoreHtml.downloadFecha(liga);
                LOG.info("Total de fechas ult 7 <" + fechaList.size() + ">");
                for (Fecha fecha : fechaList) {
                    analisisService.execute(fecha);
                    fechaRepository.save(fecha);
                }
                LOG.info("Liga " + liga.getNombre() + " total fechas " + fechaList.size());
            }
        } catch (Exception e) {
            LOG.error("Error al descarga fecha para la liga " + liga.toString(), e);
        }

    }

    public void descargarHoyIntern() {
        List<Liga> ligaList = ligaRepository.getLigaList();
        Map<String, String> leagueIdNameMap = new HashMap<String, String>();

        for (Liga liga : ligaList) {
            if (StringUtils.isNotBlank(liga.getLeagueName())) {
                leagueIdNameMap.put(liga.getLeagueName(), liga.getNombre());
            }
        }

        List<Fecha> fechaList = new ArrayList<Fecha>();
        try {
            fechaList = LiveScoreHtml.downloadHoy(leagueIdNameMap);
            LOG.info("Total de fechas ult 7 <" + fechaList.size() + ">");
            for (Fecha fecha : fechaList) {
                analisisService.execute(fecha);
                fechaRepository.save(fecha);
            }
        } catch (Exception e) {
            LOG.error("Error al descarga fecha para la liga ", e);
        }

    }

    @Transactional
    public void analizarResultados(Liga liga) {

        if (StringUtils.isBlank(liga.getUrl_campeonato())) return;

        LOG.info("Analizando liga <" + liga.getNombre() + ">");
        List<Evento> fechaList = new ArrayList<Evento>();
        try {
            List<Equipo> equipoList = equipoRepository.buscarEquipos(liga.getNombre());
            LOG.info("Analizando equipos <" + equipoList.size() + ">");
            for (Equipo equipo : equipoList) {
                List<String> nombreList = equipo.getNombreList();
                fechaList = eventoRepository.buscarFechas(liga.getLeagueId(), nombreList);
                LOG.info("total de fechas para el equipo <" + nombreList + "> es <" + fechaList.size() + ">");
                if (fechaList.isEmpty()) {
                    LOG.info(" <<<<<<<<<<<<<<<<<<" + equipo.getNombre() + "> es <" + fechaList.size() + ">");
                    continue;
                }
                analisisService.executeResultado(nombreList, equipo, fechaList);
                equipoRepository.save(equipo);
            }
            LOG.info("Liga " + liga.getNombre() + " total fechas " + fechaList.size());
            ligaRepository.save(liga);
        } catch (Exception e) {
            LOG.error("Error al descarga fecha para la liga " + liga.toString(), e);
        }
    }

    @Transactional
    public void analizarFechas(Liga liga) {

        if (StringUtils.isBlank(liga.getUrl_campeonato())) return;

        LOG.info("Analizando liga <" + liga.getNombre() + ">");
        List<Fecha> fechaList = new ArrayList<Fecha>();
        try {
            List<Equipo> equipoList = equipoRepository.buscarEquipos(liga.getNombre());
            LOG.info("Analizando equipos <" + equipoList.size() + ">");
            for (Equipo equipo : equipoList) {
                String opcional = equipo.getNombre();
                fechaList = fechaRepository.buscarFechas(liga.getNombre(), opcional);
                if (fechaList.isEmpty()) {
                    opcional = equipo.getAlias_livescore();
                    if (StringUtils.isNotBlank(opcional))
                        fechaList = fechaRepository.buscarFechas(liga.getNombre(), opcional);
                }
                LOG.info("total de fechas para el equipo <" + equipo.getNombre() + " or " + opcional + "> es <" + fechaList.size() + ">");
                if (fechaList.isEmpty()) {
                    LOG.info(" <<<<<<<<<<<<<<<<<<" + equipo.getNombre() + "> es <" + fechaList.size() + ">");
                    continue;
                }
                analisisService.execute(opcional, equipo, fechaList);
                equipoRepository.save(equipo);
            }
            LOG.info("Liga " + liga.getNombre() + " total fechas " + fechaList.size());
            ligaRepository.save(liga);
        } catch (Exception e) {
            LOG.error("Error al descarga fecha para la liga " + liga.toString(), e);
        }
    }

    @Override
    public void descargarWindrawWin() {
        descargarWinDrawWinIntern();
        eventoService.asignarWinDrawWin();
    }

    @Override
    public void loadfile(File file) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(file));
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        List<Fecha> fechaList = new ArrayList<Fecha>();
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();
//17/01/2015;SCP;Motherwell;Kilmarnock;1-1;1-1
            while (line != null) {
                String[] token = StringUtils.split(line, ';');
                Fecha fechaBean = new Fecha();
                fechaBean.setFecha(sdf.parse(token[0]));
                fechaBean.setLiga(token[1]);
                fechaBean.setEquipo1(token[2]);
                fechaBean.setEquipo2(token[3]);
                fechaBean.setPrimerTiempo(token[4]);
                fechaBean.setResultadoFinal(token[5]);
                fechaList.add(fechaBean);
                line = br.readLine();
            }
            for (Fecha fecha : fechaList) {
                analisisService.execute(fecha);
                fechaRepository.save(fecha);
            }
            String everything = sb.toString();
        } finally {
            br.close();
        }
    }

    @Transactional
    public int downloadEstadisticasLiga(final Liga liga) throws Exception {

        int totalEquipo = equipoRepository.buscarEquipos(liga.getNombre()).size();

        HtmlPage mainPage = null;
        HtmlTable detalleTable = null;
        List<HtmlTableRow> rows = null;
        WebClient webClient = new WebClient();
        webClient.setJavaScriptEnabled(false);
        webClient.setThrowExceptionOnFailingStatusCode(false);
        mainPage = webClient.getPage(liga.getUrl());
        List<Equipo> equipoList = new ArrayList<Equipo>();
        int tableIndex = 10;

        do {
            rows = buscarTableUlt8(tableIndex, liga, mainPage, totalEquipo);
            System.out.println("tableIndex:" + tableIndex + "-> rows " + (rows == null ? null : rows.size()));
            tableIndex++;
        } while (rows == null && tableIndex < 15);



        for (int j = 1; j < rows.size(); j++) {
            HtmlTableRow detailDataRow = rows.get(j);
            Equipo equipo = new Equipo();
            WebClient webClientEquipo = new WebClient();
            webClientEquipo.setJavaScriptEnabled(false);
            webClientEquipo.setThrowExceptionOnFailingStatusCode(false);
            String nombre = StringUtil.trim(detailDataRow.getCell(1).getTextContent());

            equipo = equipoRepository.findOne(new EquipoPK(liga.getNombre(), nombre));
            if (equipo == null) {
                equipo = new Equipo(nombre, liga.getNombre(), "");
            }
            equipo.setPosicion_ult_8(new Integer(StringUtil.trim(detailDataRow.getCell(0).getTextContent())));
            equipo.setTotal_g_ult_8(new Integer(StringUtil.trim(detailDataRow.getCell(3).getTextContent())));
            equipo.setTotal_e_ult_8(new Integer(StringUtil.trim(detailDataRow.getCell(4).getTextContent())));
            equipo.setTotal_p_ult_8(new Integer(StringUtil.trim(detailDataRow.getCell(5).getTextContent())));
            Integer totalPartidos = new Integer(StringUtil.trim(detailDataRow.getCell(2).getTextContent()));
            equipo.setLiga(liga.getNombre());
            equipo.setPartidos_ult_8(totalPartidos);
            equipoList.add(equipo);
        }

        do {
            rows = buscarTableGeneral(tableIndex, liga, mainPage, totalEquipo);
            System.out.println("tableIndex:" + tableIndex + "-> rows " + (rows == null ? null : rows.size()));
            tableIndex++;
        } while (rows == null && tableIndex < 18);


        if (rows != null) {

            for (int j = 1; j < rows.size(); j++) {
                HtmlTableRow detailDataRow = rows.get(j);

                WebClient webClientEquipo = new WebClient();
                webClientEquipo.setJavaScriptEnabled(false);
                webClientEquipo.setThrowExceptionOnFailingStatusCode(false);
                String nombre = StringUtil.trim(detailDataRow.getCell(1).getTextContent());

                Equipo equipoItem = new Equipo(nombre, liga.getNombre(), "");

                Equipo equipo=null;
                try {
                    equipo = equipoList.get(equipoList.indexOf(equipoItem));
                }catch (Exception ex){
                    System.out.println(ex);
                }

                equipo.setPosicion(new Integer(StringUtil.trim(detailDataRow.getCell(0).getTextContent())));
                equipo.setTotal_g(new Integer(StringUtil.trim(detailDataRow.getCell(3).getTextContent())));
                equipo.setTotal_e(new Integer(StringUtil.trim(detailDataRow.getCell(4).getTextContent())));
                equipo.setTotal_p(new Integer(StringUtil.trim(detailDataRow.getCell(5).getTextContent())));
                Integer totalPartidos = new Integer(StringUtil.trim(detailDataRow.getCell(2).getTextContent()));
                equipo.setLiga(liga.getNombre());
                equipo.setPartidos(totalPartidos);
                equipoList.add(equipo);
            }
        }

        for (Equipo equipo : equipoList) {
            equipo.setLastUpdated(new Date());
            equipoRepository.save(equipo);
        }

        return rows.size();
    }

    private List<HtmlTableRow> buscarTableUlt8(int next, Liga liga, HtmlPage mainPage, int totalEquipos) throws Exception {
        LOG.info("Buscando liga " + liga.getNombre() + " en " + liga.getUrl());

        HtmlTable detalleTable = null;

        detalleTable = HtmlUtil.getHtmlTable(mainPage, next);
        List<HtmlTableRow> rows = detalleTable.getRows();
        LOG.info("Buscando liga " + liga.getNombre() + " en " + liga.getUrl() + " equipos <" + rows.size() + ">");
        if (rows.size() == (totalEquipos + 1)) {
            return rows;
        }

        return null;
    }


    private List<HtmlTableRow> buscarTableGeneral(int next, Liga liga, HtmlPage mainPage, int totalEquipos) throws Exception {
        LOG.info("Buscando liga " + liga.getNombre() + " en " + liga.getUrl());

        HtmlTable detalleTable = null;

        detalleTable = HtmlUtil.getHtmlTable(mainPage, next);
        List<HtmlTableRow> rows = detalleTable.getRows();
        LOG.info("Buscando liga " + liga.getNombre() + " en " + liga.getUrl() + " equipos <" + rows.size() + ">");
        if (rows.size() == (totalEquipos + 1) && rows.get(0).getCells().size()>3) {
            return rows;
        }
        return null;
    }


    private void populateLeagueId(Liga liga) {

        List<Liga> ligaList = getCopaBase();

        for (Liga next : ligaList) {
            if (next.getNombre().equals(liga.getNombre())) {
                liga.setLeagueId(next.getLeagueId());
                liga.setLeagueName(next.getLeagueName());
                liga.setLeagueNamePredictz(next.getLeagueNamePredictz());
                liga.setLeagueNameWinDrawWin(next.getLeagueNameWinDrawWin());
                liga.setUrlPredictz(next.getUrlPredictz());
            }
        }

        Map<String, String> map = getMapCampeonato();

        if (map.get(liga.getNombre()) != null) {
            liga.setUrl_campeonato(map.get(liga.getNombre()));
        }
    }


    public Map<String, String> getMapCampeonato() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("Brazil", "http://www.livescore.com/soccer/brazil/serie-a-brasileiro/results/7-days/");
        map.put("Brazil2", "http://www.livescore.com/soccer/brazil/serie-b-brasileiro/results/7-days/");
        map.put("USA", "http://www.livescore.com/soccer/usa/mls/results/7-days/");
        map.put("Italy", "http://www.livescore.com/soccer/italy/serie-a/results/7-days/");
        map.put("Italy2", "http://www.livescore.com/soccer/italy/serie-b/results/7-days/");
        map.put("Argentina", "http://www.livescore.com/soccer/argentina/primera-division/results/7-days/");
        map.put("Argentina2", "http://www.livescore.com/soccer/argentina/national-b/results/7-days/");
        map.put("Germany", "http://www.livescore.com/soccer/germany/bundesliga/results/7-days/");
        map.put("Germany2", "http://www.livescore.com/soccer/germany/2-bundesliga/results/7-days/");
        map.put("England", "http://www.livescore.com/soccer/england/premier-league/results/7-days/");
        map.put("England2", "http://www.livescore.com/soccer/england/championship/results/7-days/");
        map.put("Spain", "http://www.livescore.com/soccer/spain/primera-division/results/7-days/");
        map.put("Spain2", "http://www.livescore.com/soccer/spain/segunda-division/results/7-days/");
        map.put("France", "http://www.livescore.com/soccer/france/ligue-1/results/7-days/");
        map.put("France-L2", "http://www.livescore.com/soccer/france/ligue-2/results/7-days/");
        map.put("Holland", "http://www.livescore.com/soccer/holland/eredivisie/results/7-days/");
        map.put("Belgium", "http://www.livescore.com/soccer/belgium/jupiler-pro-league/results/7-days/");
        map.put("Scotland", "http://www.livescore.com/soccer/scotland/premier-league/results/7-days/");
        map.put("Austria", "http://www.livescore.com/soccer/austria/bundesliga/results/7-days/");
        map.put("Denmark", "http://www.livescore.com/soccer/denmark/sas-ligaen/results/7-days/");
        map.put("Norway", "http://www.livescore.com/soccer/norway/tippeligaen/results/7-days/");
        map.put("Sweden", "http://www.livescore.com/soccer/sweden/allsvenskan/results/7-days/");
        map.put("Sweden2", "http://www.livescore.com/soccer/sweden/superettan/results/7-days/");
        map.put("Switzerland", "http://www.livescore.com/soccer/switzerland/super-league/results/7-days/");
//        map.put("Chile", "http://www.livescore.com/soccer/chile/apertura/results/7-days/");
        map.put("Chile", "http://www.livescore.com/soccer/chile/primera-clausura/results/7-days/");
        map.put("Colombia", "http://www.livescore.com/soccer/colombia/liga-postobon-i/results/7-days/");
        map.put("Ecuador", "http://www.livescore.com/soccer/ecuador/serie-a-apertura/results/7-days/");
        map.put("Paraguay", "http://www.livescore.com/soccer/paraguay/apertura/results/7-days/");
        map.put("Uruguay", "http://www.livescore.com/soccer/uruguay/clausura/results/7-days/");
        map.put("Norway2", "http://www.livescore.com/soccer/norway/1-division/results/7-days/");
        map.put("Finland", "http://www.livescore.com/soccer/finland/veikkausliga/results/7-days/");
        map.put("Portugal", "http://www.livescore.com/soccer/portugal/liga-sagres/results/7-days/");
        map.put("England3", "http://www.livescore.com/soccer/england/league-1/results/7-days/");
        map.put("England4", "http://www.livescore.com/soccer/england/league-2/results/7-days/");
        map.put("Mexico", "http://www.livescore.com/soccer/mexico/clausura/results/7-days/");
//        map.put("Mexico", "http://www.livescore.com/soccer/mexico/apertura/results/7-days/");
        map.put("PER", "http://www.livescore.com/soccer/peru/primera-division-apertura/results/7-days/");
        map.put("PE2", "http://www.livescore.com/soccer/peru/segunda-division/results/7-days/");
        map.put("Bolivia", "http://www.livescore.com/soccer/bolivia/primera-division-clausura/results/7-days/");
        return map;
    }


    public List<Liga> getCopaBase() {
        List<Liga> result = new ArrayList<Liga>();
        result.add(new Liga("Brazil", "BR1", "Brazil-SerieA"));
        result.add(new Liga("Argentina", "AR1", "Argentina-PrimeraDivision", "Argentina Primera A Nacional Predictions", "http://www.predictz.com/predictions/argentina/primera-a/", "ARGENTINA PRIMERA A NACIONAL"));
        result.add(new Liga("Argentina2", "AR2", "Argentina-PrimeraBNacional", "Argentina Primera B Nacional Predictions", "http://www.predictz.com/predictions/argentina/primera-a/", "ARGENTINA PRIMERA B NACIONAL"));
        result.add(new Liga("Argentina3", "AR3", ""));
        result.add(new Liga("Ecuador", "ECU", "Ecuador-SerieA::apertura", "", "", "ECUADOR PRIMERA A"));
        result.add(new Liga("Colombia", "COL", "Colombia-LigaPostobónI::clausuraplay-offgroupA", "", "", "COLOMBIA COPA MUSTANG"));
        result.add(new Liga("Paraguay", "PAR", "Paraguay-DivisionProfesional::apertura", "", "", "PARAGUAY DIVISION DE HONOR"));
        result.add(new Liga("Uruguay", "URU", "Uruguay-PrimeraDivisión::clausura", "", "", "URUGUAY DIVISION PROFESIONAL"));
        result.add(new Liga("Bolivia", "BOL", "Bolivia-PrimeraDivision::apertura"));
        result.add(new Liga("Brazil2", "BR2", "Brazil-SerieB"));
        result.add(new Liga("USA", "USA", "USA-MajorLeagueSoccer", "USA Major League Soccer Predictions", "http://www.predictz.com/predictions/usa/major-league-soccer/", "USA MAJOR LEAGUE SOCCER"));
        result.add(new Liga("Mexico", "MEX", "Mexico-PrimeraDivision::clausura", "Mexico la Division Predictions", "http://www.predictz.com/predictions/mexico/la-division/", "MEXICO LIGA MX"));
        result.add(new Liga("PERU", "PER", "Peru-PrimeraDivisión::apertura"));
        result.add(new Liga("Holland", "HOL", "Netherlands-Eredivisie", "Holland Eredivisie Predictions", "http://www.predictz.com/predictions/netherlands/eredivisie/", "HOLLAND EREDIVISIE"));
        result.add(new Liga("France", "FR1", "France-Ligue1", "France Ligue 1 Predictions", "http://www.predictz.com/predictions/france/ligue-1/", "FRANCE LIGUE 1"));
        result.add(new Liga("France-L2", "FR2", "France-Ligue2", "France Ligue 2 Predictions", "http://www.predictz.com/predictions/france/ligue-2/", "FRANCE LIGUE 2"));
        result.add(new Liga("Germany", "AL1", "Germany-Bundesliga", "Germany Bundesliga Predictions", "http://www.predictz.com/predictions/germany/bundesliga/", ""));
        result.add(new Liga("Germany2", "AL2", "Germany-2ndBundesliga", "Germany Bundesliga II Predictions", "http://www.predictz.com/predictions/germany/bundesliga-ii/", "GERMANY BUNDESLIGA II"));
        result.add(new Liga("Italy", "IT1", "Italy-SerieA", "Italy Serie A Predictions", "http://www.predictz.com/predictions/italy/serie-a/", "ITALY SERIE A"));
        result.add(new Liga("Italy2", "IT2", "Italy-SerieB", "Italy Serie B Predictions", "http://www.predictz.com/predictions/italy/serie-b/", "ITALY SERIE B"));
        result.add(new Liga("Portugal", "POR", "Portugal-PrimeiraLiga", "Portugal Superliga Predictions", "http://www.predictz.com/predictions/portugal/superliga/", "PORTUGAL SUPERLIGA"));
        result.add(new Liga("England", "INP", "England-PremierLeague", "England Premier League Predictions", "http://www.predictz.com/predictions/england/premier-league/", "ENGLAND PREMIER LEAGUE"));
        result.add(new Liga("England2", "ING", "England-Championship", "England Championship Predictions", "http://www.predictz.com/predictions/england/championship/", "ENGLAND CHAMPIONSHIP"));
        result.add(new Liga("England3", "IN1", "England-League1", "England League 1 Predictions", "http://www.predictz.com/predictions/england/league-1/", "ENGLAND LEAGUE 1"));
        result.add(new Liga("England4", "IN2", "England-League2", "England League 2 Predictions", "http://www.predictz.com/predictions/england/league-2/", "ENGLAND LEAGUE 2"));
        result.add(new Liga("Spain", "ES1", "Spain-LigaBBVA", "Spain Primera Liga Predictions", "http://www.predictz.com/predictions/spain/primera-liga/", "SPAIN PRIMERA LIGA"));
        result.add(new Liga("Spain2", "ES2", "Spain-LigaAdelante", "Spain Segunda Liga Predictions", "http://www.predictz.com/predictions/spain/segunda-liga/", "SPAIN SEGUNDA LIGA"));
        result.add(new Liga("Austria", "AU1", "Austria-Bundesliga", "Austria Bundesliga Predictions", "http://www.predictz.com/predictions/austria/bundesliga/", "AUSTRIA BUNDESLIGA"));
        result.add(new Liga("Belgium", "BEL", "Belgium-JupilerLeague", "Belgium Juliper League Predictions", "http://www.predictz.com/predictions/belgium/juliper-league/", "BELGIUM JULIPER LEAGUE"));
        result.add(new Liga("Denmark", "DIN", "Denmark-Superligaen", "Denmark Superliga Predictions", "http://www.predictz.com/predictions/denmark/superliga/", "DENMARK SUPERLIGA"));
        result.add(new Liga("Finland", "FIN", "Finland-Veikkausliiga", "Finland Veikkausliiga Predictions", "http://www.predictz.com/predictions/finland/veikkausliiga/", ""));
        result.add(new Liga("Norway2", "NO2", "Norway-1stDivision", "Norway Adeccoligaen Predictions", "http://www.predictz.com/predictions/norway/adeccoligaen/", "NORWAY ADECCOLIGAEN"));
        result.add(new Liga("Norway", "NOR", "Norway-Tippeligaen", "Norway Tippeligaen Predictions", "http://www.predictz.com/predictions/norway/tippeligaen/", "NORWAY TIPPELIGAEN"));
        result.add(new Liga("Scotland", "SCP", "Scotland-Premiership", "Scotland Premiership Predictions", "http://www.predictz.com/predictions/scotland/premiership/", "SCOTLAND PREMIERSHIP"));
        result.add(new Liga("Sweden", "SU1", "Sweden-Allsvenskan", "Sweden Allsvenskan Predictions", "http://www.predictz.com/predictions/sweden/allsvenskan/", "SWEDEN ALLSVENSKAN"));
        result.add(new Liga("Sweden2", "SU2", "Sweden-Superettan", "Sweden Superettan Predictions", "http://www.predictz.com/predictions/sweden/superettan/", "SWEDEN SUPERETTAN"));
        result.add(new Liga("Switzerland", "SUI", "Switzerland-SuperLeague"));
        result.add(new Liga("Chile", "CH1", "Chile-Primera::clausura", "", "", "CHILE PRIMERA"));
        return result;
    }

}
